
/********************************************************************************
  * @file     SD93F115B_lcd.h   						    	
  * @author   TEST TEAM 												    	
  * @version  v0															    	
  * @date     Septemper 2022												    	
  * @brief 
  *           
  * Copyright (C) 2022  Hangzhou SDIC Microelectronics Co., Ltd  
*********************************************************************************/

#ifndef __SD93F115B_LCD_H
#define __SD93F115B_LCD_H

#ifdef __cplusplus
 extern "C" {
#endif

#include "SD93F115B.h"
  
/***************** Configure the CPR clock ********************/
#define LCD_IHRC_DIV8                 	((uint8_t)0x00)			   //IHRC_DIV8 表示IHRC除以8
#define LCD_IHRC_DIV16                 	LCD_CPMR_CPRCLKS_0
#define LCD_IHRC_DIV32                 	LCD_CPMR_CPRCLKS_1
#define LCD_ILRC_MUL2                 	((uint8_t)0x60)			   //ILRC_MUL2 表示ILRC乘以2
#define LCD_ILRC                 		LCD_CPMR_CPRCLKS_2             
#define LCD_XTOSC1                 		((uint8_t)0xA0)
#define LCD_XTOSC1_DIV2                 ((uint8_t)0xC0)

#define IS_LCD_CPRCLK(CPRCLK) (((CPRCLK) == LCD_IHRC_DIV8)||((CPRCLK) == LCD_IHRC_DIV16)||\
							   ((CPRCLK) == LCD_IHRC_DIV32)||((CPRCLK) == LCD_ILRC_MUL2)||\
							   ((CPRCLK) == LCD_ILRC)||((CPRCLK) == LCD_XTOSC1)||\
							   ((CPRCLK) == LCD_XTOSC1_DIV2))

/************ Configure the CPR output Voltage **************/
#define LCD_VLCDLevel_2V7               	((uint8_t)0x00)			//表示VLCD电压为2.6V,下方以此类推
#define LCD_VLCDLevel_2V8                 	LCD_CPMR_VLCD_0
#define LCD_VLCDLevel_2V9                 	LCD_CPMR_VLCD_1
#define LCD_VLCDLevel_3V0                 	((uint8_t)0x06)			
#define LCD_VLCDLevel_3V1                 	LCD_CPMR_VLCD_2          
#define LCD_VLCDLevel_3V2                 	((uint8_t)0x0A)
#define LCD_VLCDLevel_3V3                  	((uint8_t)0x0C)
#define LCD_VLCDLevel_3V4                 	((uint8_t)0x0E)			
#define LCD_VLCDLevel_3V5                 	LCD_CPMR_VLCD_3 
#define LCD_VLCDLevel_3V6                 	((uint8_t)0x12)
#define LCD_VLCDLevel_4V2                 	((uint8_t)0x14)			
#define LCD_VLCDLevel_4V4                 	((uint8_t)0x16)             
#define LCD_VLCDLevel_4V6                 	((uint8_t)0x18)
#define LCD_VLCDLevel_4V8                  	((uint8_t)0x1A)
#define LCD_VLCDLevel_5V0                 	((uint8_t)0x1C)
#define LCD_VLCDLevel_5V2                  	((uint8_t)0x1E)

#define IS_LCD_VLCD_Level(Level) (((Level) == LCD_VLCDLevel_2V7)||((Level) == LCD_VLCDLevel_2V8)||\
								  ((Level) == LCD_VLCDLevel_2V9)||((Level) == LCD_VLCDLevel_3V0)||\
								  ((Level) == LCD_VLCDLevel_3V1)||((Level) == LCD_VLCDLevel_3V2)||\
								  ((Level) == LCD_VLCDLevel_3V3)||((Level) == LCD_VLCDLevel_3V4)||\
								  ((Level) == LCD_VLCDLevel_3V5)||((Level) == LCD_VLCDLevel_3V6)||\
								  ((Level) == LCD_VLCDLevel_4V2)||((Level) == LCD_VLCDLevel_4V4)||\
								  ((Level) == LCD_VLCDLevel_4V6)||((Level) == LCD_VLCDLevel_4V8)||\
								  ((Level) == LCD_VLCDLevel_5V0)||((Level) == LCD_VLCDLevel_5V2))

typedef enum
{
  LCDWAVE_A = 0x00,                     //LCD驱动波形为A波 
  LCDWAVE_B = 0x01,                     //LCD驱动波形为B波
  
}LCDWAVE_TypeDef;

#define IS_LCD_WAVE(WAVE) (((WAVE) == LCDWAVE_A)||((WAVE) == LCDWAVE_B))

typedef enum
{
  LCDDUTY_4COM = 0x00,                  //LCD为4COM形式  
  LCDDUTY_5COM = 0x01,                  //LCD为5COM形式  
  LCDDUTY_6COM = 0x02,                  //LCD为6COM形式  
  LCDDUTY_8COM = 0x03                   //LCD为8COM形式 
  
}LCDDUTY_TypeDef;

#define IS_LCD_DUTY(DUTY) (((DUTY) == LCDDUTY_4COM)||((DUTY) == LCDDUTY_5COM)||\
						   ((DUTY) == LCDDUTY_6COM)||((DUTY) == LCDDUTY_8COM))

typedef enum
{	
  LCDCLKS_ILRC_DIV2 = 0x00,             //LCD工作时钟为ILRC/2
  LCDCLKS_ILRC = 0x01,                  //LCD工作时钟为ILRC
  LCDCLKS_XTOSC1_DIV2 = 0x02,           //LCD工作时钟为XTOSC1/2
  LCDCLKS_XTOSC1 = 0x03                 //LCD工作时钟为XTOSC1
 
}LCDCLKS_TypeDef;

#define IS_LCD_CLKS(CLKS) (((CLKS) == LCDCLKS_ILRC_DIV2)||((CLKS) == LCDCLKS_ILRC)||\
						   ((CLKS) == LCDCLKS_XTOSC1_DIV2)||((CLKS) == LCDCLKS_XTOSC1))
						   
#define IS_LCD_BIAS(BIAS) (((BIAS) == DISABLE) || ((BIAS) == ENABLE))	
#define IS_LCD_LCDBL(BIAS) (((BIAS) == DISABLE) || ((BIAS) == ENABLE))					   
typedef enum
{	
  LCDCLKS_DIV4 = 0x00,                 //LCD工作时钟4分频，下同
  LCDCLKS_DIV8 = 0x01,          
  LCDCLKS_DIV16 = 0x02,          
  LCDCLKS_DIV32 = 0x03,
  LCDCLKS_DIV64 = 0x04,
  LCDCLKS_DIV128 = 0x05,
  LCDCLKS_DIV256 = 0x06
  
}LCDCLKS_DIV_TypeDef;

#define IS_LCDCLKS_DIV(DIV) (((DIV) == LCDCLKS_DIV4)||((CLKS) == LCDCLKS_DIV8)||\
							 ((CLKS) == LCDCLKS_DIV16)||((CLKS) == LCDCLKS_DIV32)\
						     ((CLKS) == LCDCLKS_DIV64)||((CLKS) == LCDCLKS_DIV128)||\
							 ((CLKS) == LCDCLKS_DIV256))

typedef struct
{
  uint8_t  LCDPin_Mode_COM;                       //配置相应引脚为COM脚
  uint32_t LCDPin_Mode_SEG1;                      //配置相应引脚为SEG脚
  uint32_t LCDPin_Mode_SEG2;                      //配置相应引脚为SEG脚
  
  FunctionalState BIAS;                           //使能LCD为1/4bias, ENABLE:1/4bias；DISABLE:1/3bias     
  FunctionalState LCDBL;                          //使能LCD显示按照字节寄存器的设置点亮       
  
  LCDWAVE_TypeDef LCDWAVE;                        //配置LCD驱动波形
  LCDDUTY_TypeDef LCDDUTY;                        //配置LCD为COM形式
  
  LCDCLKS_DIV_TypeDef LCDCLKS_DIV;                //配置LCD工作时钟的分频系数
  LCDCLKS_TypeDef LCDCLKS;                        //配置LCD的工作时钟
  
}LCD_InitTypeDef;

/*****Configure LCD_DR0~LCD_DR10*****/
#define LCD_DR0               	    ((uint8_t)0x00)			//配置显示数据寄存器
#define LCD_DR1                 	((uint8_t)0x01)
#define LCD_DR2                 	((uint8_t)0x02)
#define LCD_DR3                 	((uint8_t)0x03)			
#define LCD_DR4                 	((uint8_t)0x04)          
#define LCD_DR5                 	((uint8_t)0x05)
#define LCD_DR6                  	((uint8_t)0x06)
#define LCD_DR7                 	((uint8_t)0x07)			
#define LCD_DR8                 	((uint8_t)0x08) 
#define LCD_DR9                 	((uint8_t)0x09)
#define LCD_DR10                 	((uint8_t)0x0A)		
#define IS_LCD_DR(DR) (((DR) == LCD_DR0)||((DR) == LCD_DR1)||((DR) == LCD_DR2)||\
					   ((DR) == LCD_DR3)||((DR) == LCD_DR4)||\
					   ((DR) == LCD_DR5)||((DR) == LCD_DR6)||\
					   ((DR) == LCD_DR7)||((DR) == LCD_DR8)||\
					   ((DR) == LCD_DR9)||((DR) == LCD_DR10))
			
typedef struct
{
	
  uint32_t LCD_Data0;
  uint32_t LCD_Data1;
  uint32_t LCD_Data2;
  uint32_t LCD_Data3;
  uint32_t LCD_Data4;
  uint32_t LCD_Data5;
  uint32_t LCD_Data6;
  uint32_t LCD_Data7;
  uint32_t LCD_Data8;
  uint32_t LCD_Data9;
  uint32_t LCD_Data10;
  
}LCD_DRTypeDef;
					   
/*段位定义（根据实际接线做相应的调整）

				  a
				 ---
			   f| g |b
				 ---
			   e|   |c
				 ---  . dot
				  d

段位定义*/
#define		aa				((uint16_t)0x0001)
#define		bb				((uint16_t)0x0002)
#define		cc				((uint16_t)0x0004)
#define		dd				((uint16_t)0x0008)
#define		ee				((uint16_t)0x0400)
#define		ff				((uint16_t)0x0100)
#define		gg				((uint16_t)0x0200)
#define		DP			    ((uint16_t)0x0800)

/*用宏定义自动生成字形码宏定义,请勿修改*/
#define		Disp_Num0		(aa+bb+cc+dd+ee+ff)		//数字'0' 
#define		Disp_Num1		(bb+cc)					//数字'1'
#define		Disp_Num2		(aa+bb+dd+ee+gg)		//数字'2'
#define		Disp_Num3		(aa+bb+cc+dd+gg)		//数字'3'
#define		Disp_Num4		(bb+cc+ff+gg)			//数字'4'
#define		Disp_Num5		(aa+cc+dd+ff+gg)		//数字'5'
#define		Disp_Num6		(aa+cc+dd+ee+ff+gg)		//数字'6'
#define		Disp_Num7		(aa+bb+cc)				//数字'7'
#define		Disp_Num8		(aa+bb+cc+dd+ee+ff+gg)	//数字'8'
#define		Disp_Num9		(aa+bb+cc+dd+ff+gg)		//数字'9'


#define		Disp_A				(aa+bb+cc+ee+ff+gg)		//字母A
#define		Disp_b				(cc+dd+ee+ff+gg)		//字母b	
#define		Disp_c_Small		(dd+ee+gg)				//字母c
#define		Disp_C_Big			(aa+dd+ee+ff)			//字母C			
#define		Disp_d				(bb+cc+dd+ee+gg)		//字母d
#define		Disp_E				(aa+dd+ee+ff+gg)		//字母E
#define		Disp_F				(aa+ee+ff+gg)			//字母F
#define		Disp_G				(aa+cc+dd+ee+ff)		//字母G
#define		Disp_H				(bb+cc+ee+ff+gg)		//字母H
#define		Disp_I				(ee+ff)					//字母I
#define		Disp_J				(bb+cc+dd+ee)			//字母J
#define		Disp_K				(bb+dd+ee+ff+gg)		//字母K
#define		Disp_L				(dd+ee+ff)				//字母L
#define		Disp_M				(aa+cc+ee+gg)			//字母M
#define		Disp_n_Small		(cc+ee+gg)				//字母n
#define		Disp_N_Big			(aa+bb+cc+ee+ff)		//字母N
#define		Disp_o_Small		(cc+dd+ee+gg)			//字母o
#define		Disp_O_Big			Disp_Num0				//字母O
#define		Disp_P				(aa+bb+ee+ff+gg)		//字母P
#define		Disp_q				(aa+bb+cc+ff+gg)		//字母q
#define		Disp_r				(ee+gg)					//字母r	
#define		Disp_S				(aa+cc+dd+ff+gg)		//字母S
#define		Disp_T				(dd+ee+ff+gg)			//字母T
#define		Disp_u_Small		(cc+dd+ee)				//字母u
#define		Disp_U_Big			(bb+cc+dd+ee+ff)		//字母U
#define		Disp_v				(cc+dd+ee)				//字母v
#define		Disp_W				(bb+dd+ff+gg)			//字母W
#define		Disp_y				(bb+cc+dd+ff+gg)		//字母y
#define		Disp_Z				Disp_Num2				//字母Z

#define		Disp_NEG			gg						//负号-,亦即中划线
#define		Disp_Line_Top		aa						//上划线
#define		Disp_Line_Bottom	dd						//下划线
#define		Disp_BL				((uint8_t)0x00)					//全段熄灭	


/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */

void LCD_DeInit(void);                                      //将LCD相关的寄存器都恢复到上电默认值 
void LCD_Init( LCD_InitTypeDef* LCD_InitStruct);            //初始化LCD相关参数
void LCD_Cmd(FunctionalState NewState);                     //使能LCD模块 


void LCD_CPRCLKConfig(uint8_t CPRCK);                       //配置CPR的工作时钟

void LCD_CPRCmd(FunctionalState NewState);                  //使能CPR电路模块

void LCD_VLCDLevelConfig(uint8_t VLCDLevel);                //设置VLCD电平

void LCD_CLKConfig(uint8_t LCDCLKS,uint8_t LCDCLKS_DIV);    //配置LCD的工作时钟

void LCD_DRConfig(uint8_t LCD_DRx,uint32_t Data);           //对LCD单个数据显示寄存器进行配置

void LCD_StructDR(LCD_DRTypeDef* LCD_DRStruct);             //整体赋值11个数据显示寄存器


/****************************************************************/

void LCD_StructInit(void);                                 //整体初始化LCD相关参数，包括CPR,VLCD电平的设置
void LCD_DisALL(void);                                     //全显示
void LCD_ClearDisALL(void);                                //清显存



#ifdef __cplusplus
}
#endif

#endif /* __SD93F115B_LCD_H */

/****************************END OF FILE****************************/